﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using CIIS.Common;
using Contract.Domain;

namespace CIIS
{
    public partial class login : BaseForm
    {
        public login()
        {
            InitializeComponent();
        }


        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textEdit1.Text) && !string.IsNullOrEmpty(textEdit2.Text))
            {
                Framework.QueryInfo info = new Framework.QueryInfo();
                info.QueryObject = "t_sys_user";
                info.AddParam("UserCode", textEdit1.Text);
                string password = Utility.Util.GetEncryptedPassword(textEdit2.Text);
                info.AddParam("PASSWORD", password);
                Contract.Domain.t_sys_user user = dao.Dao.FindOne(info) as Contract.Domain.t_sys_user;
                if (user != null)
                {
                    Contract.Domain.Office office = dao.Dao.FindById("Office", user.DEPT_ID) as Office;
                    user.OfficeCode = office.BH;
                    base.CurrentUser = user;
                    dao.SpringCache.Insert("CurrentUser", user);
                    Main f = new Main();
                    f.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("用户名密码错误！");
                }
            }
            else
            {
                MessageBox.Show("用户密码不能空！");
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }
    }
}